<div class="row">
    <div class="col-xs-12">

        <form action="" method="POST" class="form-search">
            <table class="table table-striped table-bordered table-hover">
                <tr>
                    <td class="col-xs-3 col-sm-1">
                        <select id="search_type" name="search_type">
                            <option value="id" {{if eq "id" .search_type}}selected="selected"{{end}}>序号ID</option>
                        </select>
                    </td>

                    <td class="col-xs-3 col-sm-2">
                        <input type="text" name="search_word" value="{{.search_word}}" placeholder="关键词">
                    </td>

                    <td colspan="80">
                        <input type="button" name="search" onclick="go_search('index');" value="查询" class="btn btn-purple btn-sm"/>
                    </td>
                </tr>
            </table>
            <script type="text/javascript">
                function go_search($ac){
                    $('.form-search').attr('action',$ac).submit();
                }
            </script>
        </form>


        <div class="table-responsive">
            <table id="function-table"
                   class="table table-bordered table-hover">
                <thead>
                <tr>
                    <th class="col-sm-1">序号</th>
                    <th class="col-sm-1">网站名</th>
                    <th class="col-sm-1">类型</th>
                    <th class="col-sm-1">网站地址</th>
                    <th class="col-sm-1">时间</th>
                    <th class="col-sm-1">状态</th>
                    <th class="col-sm-1">爬取进度</th>
                    <th class="col-sm-2">
                        <a class="blue" title="新增项目" href="/{{adminPath}}/{{.curController}}/add">
                            <i class="glyphicon glyphicon-plus bigger-130"></i>
                        </a>
                    </th>
                    <th class="col-sm-1">其他操作</th>
                </tr>
                </thead>


                <tbody>
                    {{range  $k, $v := .list}}
                    <tr>
                        <td>{{$v.Id}}</td>
                        <td>{{$v.Name}}</td>
                        <td>
                            {{if eq "0" $v.IsOfficial}}<span class="badge badge-grey">民间</span>
                            {{else}}<span class="badge badge-danger">官方</span>
                            {{end}}
                        </td>
                        <td>{{$v.PageIndex}}</td>
                        <td>
                            <span class="btn btn-sm" data-rel="tooltip" title="更新时间:{{$v.CreateTime}}|创建时间:{{$v.UpdateTime}}">查看</span>
                        </td>
                        <td>
                            {{if eq 1 $v.Status}}
                            <a class="blue" href="javascript:req('/{{adminPath}}/{{$.curController}}/lock?id={{$v.Id}}')">
                                <span title="点击锁定" class="badge badge-warning">正常</span></a>
                            {{else}}
                            <a class="blue" href="javascript:req('/{{adminPath}}/{{$.curController}}/lock?id={{$v.Id}}')">
                                <span title="点击解锁" class="badge">锁定</span></a>
                            {{end}}
                        </td>
                        <td>{{.SpiderProgress}}</td>
                        <td>
                            <div class="action-buttons">
                                <a class="blue" title="编辑" href="/{{adminPath}}/{{$.curController}}/add?id={{$v.Id}}">
                                    <i class="fa fa-pencil bigger-130"></i>
                                </a>
                                {{if eq 1 $v.Status}} 
                                <a class="blue" title="点击锁定" href="javascript:req('/{{adminPath}}/{{$.curController}}/lock?id={{$v.Id}}')">
                                    <i class="fa fa-unlock bigger-130"></i>
                                </a> 
                                {{else}} 
                                <a class="blue" title="点击解锁" href="javascript:req('/{{adminPath}}/{{$.curController}}/lock?id={{$v.Id}}')">
                                <i class=" fa fa-lock bigger-130"></i>
                                </a> 
                                {{end}}
                                <a class="blue" title="删除"
                                   href="javascript:req('/{{adminPath}}/{{$.curController}}/del?id={{$v.Id}}')">
                                    <i class="fa fa-trash-o bigger-130"></i>
                                </a>
                            </div>
                        </td>
                        <td>
                            <div class="action-buttons">
                                <a class="blue" title="全站爬取"
                                   href="javascript:req('/{{adminPath}}/{{$.curController}}/allspider?id={{$v.Id}}')">
                                    <i class="fa fa-bolt bigger-130"></i>
                                </a>

                                <a class="blue a_onespider" title="单页爬取"
                                   href="javascript:;" idval="{{$v.Id}}">
                                    <i class="fa fa-book bigger-130"></i>
                                </a>
                            </div>
                        </td>
                    </tr>
                    {{end}}
                </tbody>
            </table>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-xs-12">
        <div class="dataTables_paginate paging_bootstrap">{{str2html .pageLink}}</div>
    </div>
</div>


<div id="dialog-confirm" class="hide">
    <p class="bigger-110 bolder center grey">
        <input id="one_url" type="text" placeholder="请输入爬取URL" class="form-control ui-autocomplete-input" autocomplete="off">
    </p>
    <div class="space-6"></div>
    <p class="bigger-110 bolder center grey">
        <input id="one_name" type="text" placeholder="请输入小说名" class="form-control ui-autocomplete-input" autocomplete="off">
    </p>
</div>

<script>
jQuery(function($) {
//jQuery start

$( ".a_onespider" ).on('click', function(e) {
    e.preventDefault();
    var id = $(this).attr("idval");
    // console.log(id);
    $( "#dialog-confirm" ).removeClass('hide').dialog({
        resizable: false,
        width: '320',
        modal: true,
        title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon blue'></i>请输入要爬取的地址[要符合规范]</h4></div>",
        title_html: true,
        buttons: [
            {
                text: "OK",
                "class" : "btn btn-danger btn-minier",
                click: function() {
                    var spider = '/{{adminPath}}/{{$.curController}}/onespider?id='+id;
                    var one_url = $("#one_url").val();
                    var one_name = $("#one_name").val();
                    if (one_url == "" || one_name == "") {
                        alert("必须输入全参数");
                        return;
                    }

                    spider += "&url="+one_url;
                    spider += "&name="+one_name;

                    $.getJSON(spider, function (data) {
                        if (data['code'] == 0) {
                            alert('操作成功！');
                            $( this ).dialog( "close" );
                            refresh();
                        } else{
                            alert(data["msg"]);
                        }
                    });
                }
            },{
                html: "<i class='ace-icon fa fa-times bigger-110'></i>&nbsp;取消",
                "class" : "btn btn-minier",
                click: function() {
                    $( this ).dialog( "close" );
                }
            }
        ]
    });
});

//jQuery end
});
</script>
